package com.ruoyi.projects.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.projects.domain.SlMemberCard;
import com.ruoyi.projects.service.ISlMemberCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户会员卡Controller
 * 
 * @author yangz
 * @date 2024-12-01
 */
@RestController
@RequestMapping("/projects/SlMemberCard")
public class SlMemberCardController extends BaseController
{
    @Autowired
    private ISlMemberCardService slMemberCardService;

    /**
     * 查询用户会员卡列表
     */
    @PreAuthorize("@ss.hasPermi('projects:SlMemberCard:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlMemberCard slMemberCard)
    {
        startPage();
        List<SlMemberCard> list = slMemberCardService.selectSlMemberCardList(slMemberCard);
        return getDataTable(list);
    }

    /**
     * 导出用户会员卡列表
     */
    @PreAuthorize("@ss.hasPermi('projects:SlMemberCard:export')")
    @Log(title = "用户会员卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlMemberCard slMemberCard)
    {
        List<SlMemberCard> list = slMemberCardService.selectSlMemberCardList(slMemberCard);
        ExcelUtil<SlMemberCard> util = new ExcelUtil<SlMemberCard>(SlMemberCard.class);
        util.exportExcel(response, list, "用户会员卡数据");
    }

    /**
     * 获取用户会员卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('projects:SlMemberCard:query')")
    @GetMapping(value = "/{cardId}")
    public AjaxResult getInfo(@PathVariable("cardId") Long cardId)
    {
        return AjaxResult.success(slMemberCardService.selectSlMemberCardByCardId(cardId));
    }

    /**
     * 新增用户会员卡
     */
    @PreAuthorize("@ss.hasPermi('projects:SlMemberCard:add')")
    @Log(title = "用户会员卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlMemberCard slMemberCard)
    {
        return toAjax(slMemberCardService.insertSlMemberCard(slMemberCard));
    }

    /**
     * 修改用户会员卡
     */
    @PreAuthorize("@ss.hasPermi('projects:SlMemberCard:edit')")
    @Log(title = "用户会员卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlMemberCard slMemberCard)
    {
        return toAjax(slMemberCardService.updateSlMemberCard(slMemberCard));
    }

    /**
     * 删除用户会员卡
     */
    @PreAuthorize("@ss.hasPermi('projects:SlMemberCard:remove')")
    @Log(title = "用户会员卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cardIds}")
    public AjaxResult remove(@PathVariable Long[] cardIds)
    {
        return toAjax(slMemberCardService.deleteSlMemberCardByCardIds(cardIds));
    }
}
